package com.taotao.netty.protobuf.server;

import com.taotao.netty.protobuf.MyMutiDataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Description:
 * @Author: TaoJF
 * @Date: Created in 2018/6/30 下午9:04
 */
public class ProtobufServerHandler extends SimpleChannelInboundHandler<MyMutiDataInfo.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyMutiDataInfo.MyMessage msg) throws Exception {
        MyMutiDataInfo.MyMessage.DataType dataType = msg.getDataType();
        if (dataType == MyMutiDataInfo.MyMessage.DataType.PersonType) {
            MyMutiDataInfo.Person person = msg.getPerson();
            System.out.println(person);
        } else if (dataType == MyMutiDataInfo.MyMessage.DataType.DogType) {
            MyMutiDataInfo.Dog dog = msg.getDog();
            System.out.println(dog);
        }else if (dataType == MyMutiDataInfo.MyMessage.DataType.CatType){
            MyMutiDataInfo.Cat cat = msg.getCat();
            System.out.println(cat);
        }
        System.out.println(msg);
        System.out.println("----------------");
    }

}
